home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Snippets / CopyBits Demo / MyAlerts.p < prev    next >
Encoding:
Text File  |  1995-10-23  |  4.0 KB  |  128 lines  |  [TEXT/MWPS]

  1. {
  2. { MyAlerts.p
  3. {
  4. { Pascal version by Bill Catambay
  5. { Original C version by Kenneth Worley
  6. { Public Domain
  7. {
  8. {
  9. { Routines that make it easier to show a quick error or
  10. { informational dialog.
  11. }
  12. Unit MyAlerts;
  13.  
  14. Interface
  15.  
  16. Uses
  17.     Types, Dialogs, TextUtils, Resources, QDOffscreen;
  18.     
  19. Procedure DoAlert(DialogID: integer; playAlert: boolean);
  20. Procedure DoAlertStrID(dialogID: integer; playAlert: boolean;
  21.                        errStrID: integer);
  22. Procedure DoAlertStrIndexID(dialogID: integer; playAlert: boolean; 
  23.                             errStrID, index: integer);
  24. Procedure DoAlertStr(dialogID: integer; playAlert: boolean;
  25.                      errString: str255);
  26.  
  27. Implementation
  28.  
  29. Procedure DoAlert(DialogID: integer; playAlert: boolean);
  30. {
  31.     This routine calls DoAlertStr with an empty error string. It is
  32.     expected that the dialog ID you specify is a dialog that already
  33.     has appropriate error text in it.
  34. }
  35.     begin
  36.     DoAlertStr(dialogID, playAlert, '');
  37.     end;
  38.  
  39. Procedure DoAlertStrID(dialogID: integer; playAlert: boolean;
  40.                        errStrID: integer);
  41. {
  42.     This routine loads the 'STR ' resource with ID errStrID and sends
  43.     the string and other parameters on to DoAlertStr.
  44. }
  45. Var    
  46.     errString:    StringHandle;
  47.     
  48.     begin
  49.     errString := GetString(errStrID);
  50.     HLock(Handle(errString));
  51.     DoAlertStr(dialogID, playAlert, errString^^);
  52.     HUnlock(Handle(errString));
  53.     ReleaseResource(Handle(errString));
  54.     end;
  55.  
  56. Procedure DoAlertStrIndexID(dialogID: integer; playAlert: boolean; 
  57.                             errStrID, index: integer);
  58. {
  59.     This routine loads the string in the 'STR#' resource at the index
  60.     specified and passes the string and other parameters to the
  61.     DoAlertStr routine.
  62. }
  63. Var
  64.     errString:    Str255;
  65.     
  66.     begin
  67.     GetIndString( errString, errStrID, index );
  68.     DoAlertStr( dialogID, playAlert, errString );
  69.     end;
  70.  
  71. Procedure DoAlertStr(dialogID: integer; playAlert: boolean;
  72.                      errString: str255);
  73. {
  74.     This routine displays an alert whose resource ID number is specified
  75.     in the parameter dialogID.  The dialog specified is expected to have
  76.     at least one button (usually labeled "OK") which will be the default
  77.     button and have an ID if 1.  When the user presses this button, the
  78.     alert will be dismissed. The dialog should also have a static text
  79.     item with an ID of 2. If the string in errString is not zero length,
  80.     that string is displayed in the static text field. If the string
  81.     is zero length, nothing is done with the text in the dialog.
  82. }
  83. Var
  84.     currentPort:    CGrafPtr;    { store the current port here }
  85.     currentDev:        GDHandle;        { store current device here }
  86.     theDlg:            DialogPtr;            { to store our dialog in }
  87.     itemType:        integer;        { these 3 local variables are used to }
  88.     itemHandle:        Handle;        { manipulate items in the dialog.     }
  89.     itemRect:        Rect;
  90.     itemHit:        integer;        { use with ModalDialog }
  91.  
  92.     begin
  93.     { Save the current grafPort }
  94.     GetGWorld( currentPort, currentDev );
  95.     { Now, load our dialog resource. }
  96.     theDlg := GetNewDialog( dialogID, NIL, WindowPtr(-1) );
  97.     { make the dialog the current port }
  98.     SetGWorld(CGrafPtr(theDlg), NIL );
  99.     { if the parameter specifies, do a system beep }
  100.     if playAlert then
  101.         SysBeep( 3 );
  102.     { If a string was sent, put that string in the dialog. }
  103.     if errString <> '' then
  104.         begin
  105.         GetDialogItem( theDlg, 2, itemType, itemHandle, itemRect );
  106.         SetDialogItemText( itemHandle, errString );
  107.         end;
  108.     { now make sure the dialog is visible }
  109.     ShowWindow( theDlg );
  110.     {    Get the OK button item and draw a bold border around it to show that
  111.     {    it's the default button. }
  112.      GetDialogItem( theDlg, 1, itemType, itemHandle, itemRect );
  113.      InsetRect( itemRect, -4, -4 );
  114.      PenSize( 3, 3 );
  115.      FrameRoundRect( itemRect, 16, 16 );
  116.      PenSize( 1, 1 );
  117.     {    Loop and call ModalDialog until the user presses the OK button
  118.     { This routine requires that whatever alert is shown, the button with
  119.     { id number kAlertOKButton is the one that should dismiss the dialog. }
  120.      ModalDialog( NIL, itemHit );
  121.      while itemHit <> 1 do
  122.          ModalDialog( NIL, itemHit );
  123.     {    Now get rid of the dialog and set the port back to the control panel }
  124.      DisposeDialog( theDlg );
  125.      SetGWorld( currentPort, currentDev );
  126.     end;
  127.  
  128. End.